/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: DriverBalanceMainServiceImpl
 * Author:   李毅
 * Date:     2019/10/31 16:34
 * Description: 司机结算业务实现类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.ymtms.settlement.service.impl;

import com.ymtms.settlement.dao.DriverBalanceMainMapper;
import com.ymtms.settlement.exception.BalanceException;
import com.ymtms.settlement.pojo.DriverBalanceMain;
import com.ymtms.settlement.service.DriverBalanceMainService;
import com.ymtms.settlement.vo.GridRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈司机结算业务实现类〉
 *
 * @author 李毅
 * @create 2019/10/31
 * @since 1.0.0
 */
@Service
public class DriverBalanceMainServiceImpl implements DriverBalanceMainService {

    @Autowired
    DriverBalanceMainMapper driverBalanceMainMapper;

    @Override
    public DriverBalanceMain findDriverBalanceMainByCode(String code) {
        DriverBalanceMain driverBalanceMain = driverBalanceMainMapper.selectByCode(code);
        return driverBalanceMain;
    }

    @Override
    public void addDriverBalanceMain(DriverBalanceMain driverBalanceMain) {
        int row = driverBalanceMainMapper.insert(driverBalanceMain);
        if (row==0) {
            throw new BalanceException("插入数据失败，请重试！");
        }
    }

    @Override
    public void updateDriverBalanceMain(DriverBalanceMain driverBalanceMain) {
        int row = driverBalanceMainMapper.updateByPrimaryKey(driverBalanceMain);
        if (row ==0 ) {
            throw new BalanceException("更新数据失败，请重试！");
        }
    }

    @Override
    public List<DriverBalanceMain> findDriverBalanceMainByState(GridRequest gridRequest,String code) {
        Integer end = gridRequest.getLimit();
        Integer start = (gridRequest.getPage()-1)*end;
        List<DriverBalanceMain> driverBalanceMains = driverBalanceMainMapper.selectByState(start,end,code);
        if (driverBalanceMains.isEmpty()){
            throw new BalanceException("查找数据失败！");
        }
        return driverBalanceMains;
    }

    @Override
    public Integer findCount(String code) {
        int row = driverBalanceMainMapper.selectCount(code);
        if (row == 0){
            throw new BalanceException("查询数量失败！");
        }
        return row;
    }

    @Override
    public void deleteDriverBalance(Integer dbid) {
        int row = driverBalanceMainMapper.updateByDbid(dbid);
        if (row == 0){
            throw new BalanceException("删除失败！");
        }
    }
}